import React, { useEffect, useRef, useState } from "react";
import {
  saveInviterRule,
  getInviterRules,
  blackCustomer,
  getAllCustomerLevels,
  getCustomerDetail,
  getCustomers,
  modifyCustomerLevel,
  transferCustomer,
  updateCustomerRemark
} from "@/services/customer/customer";
import { Form } from "antd";
import {
  ActionType,
  ModalForm,
  PageContainer,
  ProColumns,
  ProFormSelect,
  ProFormTextArea,
  ProFormTreeSelect,
  ProFormText,
  ProForm,
  ProTable,
  ProFormInstance
} from "@ant-design/pro-components";
import {
  Button,
  Checkbox,
  Col,
  DatePicker,
  message,
  Row,
  Spin,
  Switch,
  Tabs,
  Tooltip,
  TreeDataNode,
  TreeSelect,
  Table, Space,
} from "antd";
import { getDepartmentMembers, getDepartments } from "@/services/department/department";
import moment from 'moment';
import { useModel } from "@@/exports";
import { DEPARTMENT_MANAGE, SALES_MANAGE } from "@/global.style";
import { getGroups } from "@/services/group/group";

const CustomerManage = () => {
  const [loading, setLoading] = useState(false);
  const { initialState, setInitialState } = useModel('@@initialState');

  const actionRef = useRef<ActionType>();
  const remarkRef = useRef();
  const modifyRef = useRef<ActionType>()
  const quizRef = useRef();
  const inviteRef = useRef();
  const levelRef = useRef();

  const [modal, setModal] = useState(false)
  const [memoModal, setMemoModal] = useState(false)
  const [levelModal, setLevelModal] = useState(false)
  const [moveModal, setMoveModal] = useState(false)
  const [record, setRecord] = useState(null)

  const [departments, setDepartments] = useState([])
  const [sales, setSales] = useState([])
  const [wechatGroups, setWechatGroups] = useState([])
  const [detail, setDetail] = useState(null)
  const [levelMap, setLevelMap] = useState([])
  const [levels, setLevels] = useState([])
  const [customers, setCustomers] = useState([])
  const [chkAll, setChkAll] = useState(false)

  const [currentIndex, setCurrentIndex] = useState(0)
  const [size, setSize] = useState(10)
  const [selectedRowKeys, setSelectedRowKeys] = useState([]);
  const shouldShowModifyRecord = (roles) => {
    const restrictedRoles = [DEPARTMENT_MANAGE, SALES_MANAGE];
    return !roles.some(role => restrictedRoles.includes(role));
  }

  const formRef = useRef<ProFormInstance>();
  const [id,setId] = useState()
  useEffect(() => {
    // const res =  
    // console.log(res)
    
  }, [])

  return (
    <PageContainer>
      <Spin spinning={loading} tip="加载中...">

        <ProForm
        formRef={formRef}
        request={() => {
          return getInviterRules().then((res:any)=>{
            setId(res.id)
            return res?{
              departmentName:res.num
            }:{}
          })
        }}
          style={{
            background: '#fff',
            padding: 20,
          }}
          onFinish={async (values) => {
            const params = {
              num:Number(values.departmentName),
              id
            }
  
            console.log(params)
            const res = await saveInviterRule(params)
            
            if (res.code !== 1) {
              message.error('提交失败')
              return false
            } else {
              message.success('提交成功')
              return true;
            }
          }}
        >
          <ProFormText
            width="md"
            name="departmentName"
            label="邀约人数"
            rules={[{ required: true, message: '请输入邀约人数' }]}
            // tooltip="最长为 24 位"
            placeholder="请输入邀约人数"

          />

          {/* <Button type="primary" htmlType="submit">
            Submit
          </Button> */}
        </ProForm>





      </Spin>
    </PageContainer>
  )
}


export default CustomerManage
